import datetime
from applications.extensions import db
from .spider_category import CategoryModel


class UrlModel(db.Model):
    __tablename__ = 'spider_url'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment="Url的ID")
    title = db.Column(db.String(255))
    href = db.Column(db.String(255), nullable=True)
    content = db.Column(db.String(255), comment='通知内容|html文件路径')
    time = db.Column(db.String(255), comment='通知发布时间')
    finish = db.Column(db.Integer, comment='是否完成任务')
    enable = db.Column(db.Integer, comment='是否启用')
    details = db.Column(db.String(255), comment='详情|来源')
    remark = db.Column(db.String(255), comment='备注|关键字')
    create_at = db.Column(db.DateTime, default=datetime.datetime.now, comment='创建时间')
    update_at = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='创建时间')
    category_id = db.Column(db.Integer, db.ForeignKey("spider_category.id"))
    category = db.relationship("CategoryModel", backref=db.backref("urls", order_by=create_at.desc()))
